<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%--
  Created by IntelliJ IDEA.
  User: 李林
  Date: 2020/3/31
  Time: 17:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--考勤界面--%>
<%--显示：考勤情况--%>
<%--显示：最近出勤情况--%>
<%--添加加班记录--%>

<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>ERP后台主页</title>
    <meta name="description" content="ERP后台主页">
    <meta name="keywords" content="ERP后台主页">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/iCheck/square/blue.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/morris/morris.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/datepicker/datepicker3.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/treeTable/jquery.treetable.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/treeTable/jquery.treetable.theme.default.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/select2/select2.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/colorpicker/bootstrap-colorpicker.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/bootstrap-markdown/css/bootstrap-markdown.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/css/style.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/ionslider/ion.rangeSlider.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/ionslider/ion.rangeSlider.skinNice.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/bootstrap-slider/slider.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/pages/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
</head>

<body class="hold-transition skin-yellow-light sidebar-mini">

<div class="wrapper">

    <!-- 页面头部 -->
    <jsp:include page="../header.jsp"></jsp:include>
    <!-- 页面头部 /-->

    <!-- 导航侧栏 -->
    <jsp:include page="../aside.jsp"></jsp:include>
    <!-- 导航侧栏 /-->

    <!-- 内容区域 -->
    <div class="content-wrapper onjsp">

        <!-- ========================================== -->
        <!--弹出层时背景层DIV-->
        <div id="fade" class="black_overlay" style="display: none;">
        </div>
        <div id="MyDiv" class="white_content_small" style="display: none;">
            <div style="text-align: right; cursor: default; height: 40px;">
                <!-- <span style="font-size: 16px;" onclick="CloseDiv('MyDiv','fade')">关闭</span> -->

            </div>
            <div style="height: 150px;width: 200px;margin: 20px auto;">
                <div style="margin: 10px auto;">
                    <button type="button" class="btn btn-info " style="margin-bottom:10px;width: 200px;" onclick="ovtime(1)">加班一小时</button>
                    <button type="button" class="btn btn-info " style="margin-bottom:10px;width: 200px;" onclick="ovtime(2)">加班俩小时</button>
                    <button type="button" class="btn btn-default " style="margin-bottom:10px;width: 200px;" onclick="CloseDiv('MyDiv','fade')">返回</button>
                </div>
            </div>
        </div>
        <section class="content-header">
            <h1>
                新闻编辑页
                <small>写出你的态度</small>
            </h1>
            <ol class="breadcrumb">
                <%--<li><a href="all-admin-index.html"><i class="fa fa-dashboard"></i> 首页</a></li>--%>
            </ol>
        </section>
        <section class="content">
            <div class="row">
                <div class="col-md-2">
                    <!-- Widget: user widget style 1 -->
                    <div class="box box-widget widget-user-2">
                        <!-- Add the bg color to the header using any of the bg-* classes -->
                        <div class="widget-user-header bg-yellow" style="height: 144px;">
                            <div class="widget-user-image">
                                <img class="img-circle" src="${pageContext.request.contextPath}/pages/img/user7-128x128.jpg" alt="User Avatar">
                            </div>
                            <!-- /.widget-user-image -->
                            <h3 class="widget-user-username"><security:authentication property="name"/></h3>
                            <input type="hidden" id="uid_inp" value='<security:authentication property="principal.uid"/>'>
                            <%--<h1 style="display: none" ><secutity:authentication property="uid"/></h1>--%>
                            <h5 class="widget-user-desc">今天也是美好的一天</h5>
                        </div>

                        <!-- <button type="button" class="btn btn-block btn-info btn-lg">Info</button>
                        <button type="button" class="btn btn-block btn-info btn-lg">Info</button> -->
                        <!-- <div class="box-footer no-padding"> -->
                        <div class="box-footer no-padding">
                            <ul class="nav nav-stacked text-center">
                                <li style="height: 73px;line-height: 50px;font-size: 20px;"><a href="#" id="sign_in_a">打卡</a></li>
                                <li style="height: 73px;line-height: 50px;font-size: 20px;"><a href="#" id="daka_a" onclick="ShowDiv('MyDiv','fade')">加班</a></li>
                                <li style="height: 74px;line-height: 50px;font-size: 20px;"><a href="#">请假</a></li>
                            </ul>
                        </div>
                    </div>
                    <!-- /.widget-user -->
                </div>
                <div class="col-md-6">
                    <!-- LINE CHART -->
                    <div class="box box-info">
                        <div class="box-header with-border">
                            <h3 class="box-title">近日考勤比例</h3>

                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                            </div>
                        </div>
                        <div class="box-body chart-responsive">
                            <div class="chart" id="line-chart" style="height: 300px;"></div>
                        </div>
                        <!-- /.box-body -->
                    </div>


                </div>
                <!-- /.col (LEFT) -->
                <div class="col-md-4">
                    <!-- DONUT CHART -->
                    <div class="box box-danger">
                        <div class="box-header with-border">
                            <h3 class="box-title">今日考勤</h3>

                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                                </button>
                                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                            </div>
                        </div>
                        <div class="box-body chart-responsive">
                            <div class="chart" id="sales-chart" style="height: 300px; position: relative;"></div>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->

                </div>
                <!-- /.col (RIGHT) -->

            </div>
            <!-- /.row -->
            <div class="box" style="margin-bottom: 0">
                <div class="box-header">
                    <h2 style="float: left;margin-top: 12px;" onclick="">签到查询</h2>
                    <div style="width: 500px;float: right;">
                        <form action="#" method="get" class="sidebar-form">
                            <div class="input-group">
                                <input type="text" id="at_input" name="search_inp" class="form-control search_inp" placeholder="搜索...">
                                <span class="input-group-btn">
                                            <button type="button" name="search" id="at_button" onclick="searchOneAt()"  class="btn btn-flat"><i class="fa fa-search"></i>
                                            </button>
                                </span>
                            </div>
                        </form>
                    </div>
                    <div style="width: 100px;float: right;margin-top: 10px;height: 36px">
                        <select id="at_sel" name="wagesLevel" class="form-control" style="height: 36px">
                            <option value="1">员工ID</option>
                            <option value="2">用户名</option>
                            <option value="3">姓名</option>
                        </select>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <table id="at_table" class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>UID</th>
                            <th>用户名</th>
                            <th>姓名</th>
                            <th>日期</th>
                            <th>上班时间</th>
                            <th>下班时间</th>
                            <th>今日状态</th>
                            <th>加班</th>
                        </tr>
                        </thead>
                    </table>
                </div>
                <!-- /.box-body -->
            </div>

        </section>
        <!-- ========================================== -->


    </div>
    <!-- 内容区域 /-->

    <!-- 底部导航 -->
    <jsp:include page="../foot.jsp"></jsp:include>
    <!-- 底部导航 /-->

</div>


<script src="${pageContext.request.contextPath}/pages/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/jQueryUI/jquery-ui.min.js"></script>
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/raphael/raphael-min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/morris/morris.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/knob/jquery.knob.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/daterangepicker/moment.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/daterangepicker/daterangepicker.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/daterangepicker/daterangepicker.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/fastclick/fastclick.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/iCheck/icheck.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/adminLTE/js/app.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/treeTable/jquery.treetable.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/select2/select2.full.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-markdown/js/bootstrap-markdown.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-markdown/locale/bootstrap-markdown.zh.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-markdown/js/markdown.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-markdown/js/to-markdown.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/ckeditor/ckeditor.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/input-mask/jquery.inputmask.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/input-mask/jquery.inputmask.extensions.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/chartjs/Chart.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/flot/jquery.flot.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/flot/jquery.flot.resize.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/flot/jquery.flot.pie.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/flot/jquery.flot.categories.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/ionslider/ion.rangeSlider.min.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-slider/bootstrap-slider.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/pages/plugins/baiduTemplate/baiduTemplate.js"></script>
<script>
    $(document).ready(function() {
        // 选择框
        $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });

    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }

    $(document).ready(function() {
        // 激活导航位置
        setSidebarActive("admin-index");
    });
</script>
</body>
</html>
<script>
    $(function (){
        issign();
        attendance();
        atRecently();
        showtable($("#uid_inp").val(),1);
    });
    function attendance(){
        $.get("${pageContext.request.contextPath}/admin/attendance/atnow",{},function (data) {
            var list = data.resultList;
            var counts = list["counts"];
            if(counts == null){
                attendance();
                return ;
            }
            donutchart(counts);
        })
    }

    function atRecently(){
        $.get("${pageContext.request.contextPath}/admin/attendance/atrecently",{},function (data) {
            var list = data.resultList;
            var atrecs = list["atrecs"];
            linechart(atrecs);
        })
    }

    function searchOneAt() {
        var search = $("#at_input").val();
        var flag = $("#at_sel").val();
        var oldTable = $('#at_table').dataTable();
        oldTable.fnClearTable(); //清空一下table
        oldTable.fnDestroy(); //还原初始化了的dataTable
        showtable(search,flag);
    }

    function signinup() {
        alert("上班打卡");
        $.post("${pageContext.request.contextPath}/admin/attendance/signin",{sign:1},function (data) {
            alert("上班打卡成功");
            $("#sign_in_a").val("已打卡");
            window.location.href = '${pageContext.request.contextPath}/admin/attendance';
        })
    }
    function signindown() {
        alert("下班打卡");
        $.post("${pageContext.request.contextPath}/admin/attendance/signin",{sign:2},function (data) {
            alert("下班打卡成功");
            $("#sign_in_a").val("已打卡");
            window.location.href = '${pageContext.request.contextPath}/admin/attendance';
        })
    }
    function issign(){
        var six = new Date();
        six.setHours(18,0,0);
        var date = new Date();
        var flag = date<six?true:false;
        $.get("${pageContext.request.contextPath}/admin/attendance/issign",{},function (data) {
            var list = data.resultList;
            var flags = list["flags"];
            if(flags[0] == true ){
                if(flag){
                    $("#sign_in_a").html("已打卡");
                }else if(flags[1]){
                    // alert("今天很棒");
                    $("#sign_in_a").html("今天很不错");
                }else {
                    // alert("下午打卡");
                    $("#sign_in_a").click(signindown);
                }
            }else {
                $("#sign_in_a").click(signinup);
            }
            if(flags[2] == true){
                $("#daka_a").html("注意身体");
                $("#daka_a").removeAttr('onclick');
            }
        })
    }
    function ovtime(sign) {
        CloseDiv('MyDiv','fade');
        $.post("${pageContext.request.contextPath}/admin/attendance/overtime",{"sign":sign},function (data) {
            alert(data.message);
            $("#daka_a").html("注意身体");
            $("#daka_a").removeAttr('onclick');
            // window.location.href
        })
    }

    function linechart(list) {
        "use strict";
        var listStr = [];
        for(var i = 0 ; i <list.length;i++){
            var s = (list[i].atcount/list[i].usercount);
            listStr.push({y: ''+list[i].date,item1:s })
        }
        var line = new Morris.Line({
            element: 'line-chart',
            resize: true,
            data: listStr,
            xkey: 'y',
            ykeys: ['item1'],
            labels: ['比例'],
            ymax: 1,
            lineColors: ['#3c8dbc'],
            hideHover: 'auto',
            units: '%'
        });
    }

    function donutchart(list) {
        var listStr = [{label: "签到人数" , value: list.atcount},{label: "未签到人数" , value: list.usercount-list.atcount}];
        var donut = new Morris.Donut({
            element: 'sales-chart',
            resize: true,
            colors: ["#3c8dbc", "#f56954"],
            data: listStr,
            hideHover: 'auto'
        });
    }

    function showtable(search,flag) {
        var username = '';
        var name = '';
        var uid = '';
        if(flag == 1)
            uid = search;
        else if(flag == 2)
            username = search;
        else name = search;
        $('#at_table').DataTable({
            "paging": true,
            "lengthChange": false,
            "ordering": false,
            "info": true,
            "autoWidth": false,
            "searching": false,
            // "serverSide": true,
            "pageLength": 5,
            ajax: function (data, callback, settings) {
                //封装请求参数
                var param = {};
                // param.pageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                // param.start = data.start;//开始的记录序号
                // param.currentPage = (data.start / data.length) + 1;//当前页码
                param.uid = uid;
                param.username = username;
                param.name = name;
                // console.log(param);
                //ajax请求数据
                $.ajax({
                    type: "GET",
                    url: "${pageContext.request.contextPath}/admin/attendance/attable",
                    cache: false, //禁用缓存
                    data: param, //传入组装的参数
                    dataType: "json",
                    success: function (resultMap) {
                        var result = resultMap.resultList["attable"];
                        var returnData = {};
                        returnData.draw = data.startRow;//这里直接自行返回了draw计数器,应该由后台返回
                        returnData.recordsTotal = result.total;//返回数据全部记录
                        returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
                        returnData.data = result.list;//返回的数据列表
                        //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕
                        callback(returnData);
                    }
                });
            },
            "columns": [
                //跟你要显示的字段是一一对应的。我这里只显示八列
                {'data': 'uid'},
                {'data': function (row, type, val, meta) {
                        return row.userInfo.username;
                    }
                },
                {'data': function (row, type, val, meta) {
                        return row.userInfo.name;
                    }
                },
                {'data': 'date'},
                {'data': 'starttime'},
                {'data': 'endtime'},
                {'data': function (row, type, val, meta) {
                        var status = row.status;
                        if(status == 1){
                            return '正常';
                        }else if(status == 2){
                            return '迟到';
                        }else {
                            return '旷工';
                        }
                    }
                },
                {'data': function (row, type, val, meta) {
                        var atsign = row.sign;
                        if(atsign == 0){
                            return '未加班';
                        }else return '加班';
                    }
                }
            ],
            language: {
                "sProcessing": "处理中...",
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "表中数据为空",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                },
                "oAria": {
                    "sSortAscending": ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            }
        })
    }
</script>
<style>
    .black_overlay {
        display: none;
        position: absolute;
        top: 0%;
        left: 0%;
        width: 100%;
        height: 100%;
        /* background-color: black; */
        z-index: 1001;
        -moz-opacity: 0.8;
        opacity: .80;
        filter: alpha(opacity=80);
    }

    .white_content {
        display: none;
        position: absolute;
        top: 10%;
        left: 10%;
        width: 80%;
        height: 80%;
        border: 5px solid lightblue;
        background-color: white;
        z-index: 1002;
        overflow: auto;
    }

    .white_content_small {
        display: none;
        position: absolute;
        top: 20%;
        left: 30%;
        width: 40%;
        height: 30%;
        border: 5px solid lightblue;
        background-color: white;
        z-index: 1002;
        overflow: auto;
    }
</style>
<script type="text/javascript">
    //弹出隐藏层
    function ShowDiv(show_div, bg_div) {
        document.getElementById(show_div).style.display = 'block';
        document.getElementById(bg_div).style.display = 'block';
        var bgdiv = document.getElementById(bg_div);
        bgdiv.style.width = document.body.scrollWidth;
        $("#" + bg_div).height($(document).height());
    }
    //关闭弹出层
    function CloseDiv(show_div, bg_div) {
        document.getElementById(show_div).style.display = 'none';
        document.getElementById(bg_div).style.display = 'none';
    }
</script>